import http from '@ohos.net.http';
import Response from '../utils/Response';
export function request(url: string,method: http.RequestMethod, requestData: any){
  const BASE_URL = 'http:127.0.0.1/api'
  let httpRequest  = http.createHttp()
  let responseResult = httpRequest .request(BASE_URL+ url,{
    method:method,
    extraData: requestData,
    header: {
      'Content-Type': 'application/json'
    },
    connectTimeout: 60000,
    readTimeout: 60000
  })
  return responseResult
  let response  = new Response()

  return responseResult.then((value:http.HttpResponse) =>{
    if (value.responseCode === 200) {
      let res: Response = JSON.parse(`${value.result}`);
      response .message = res.message
      response .data = res.data
    }else {
       response.message = '请求错误';
       response.code = 400;
     }
     return response;
  }).catch(() => {
    response.message = '请求错误';
    response.code = 400;
    return response;
  })
}